package com.dragon.modules.yuegou.service.impl.merchant;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.merchant.UserJpushMessageEntity;
import com.dragon.modules.yuegou.mapper.merchant.UserJpushMessageMapper;
import com.dragon.modules.yuegou.model.merchant.UserJpushMessage;
import com.dragon.modules.yuegou.query.merchant.UserJpushMessageQuery;
import com.dragon.modules.yuegou.service.merchant.UserJpushMessageService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 商户用户极光IM对应关系表 服务实现
 *
 * @author pbuilder generated
 * @date 2020-03-11 16:02:02
 * @version 2.0
 */
@Service("merUserJpushMessageService")
public class UserJpushMessageServiceImpl
		extends ServiceImpl<UserJpushMessageMapper, UserJpushMessageEntity>
		implements UserJpushMessageService {

	@Override
	public UserJpushMessage getByMerchantUser(String userId) {
		UserJpushMessageQuery query = new UserJpushMessageQuery();
		query.setMerchantUserId(userId);
		query.setStatus(false);
		List<UserJpushMessageEntity> entities = list(query.toQueryWrapper());
		if (CollectionUtils.isEmpty(entities)){
			return new UserJpushMessage();
		}
		return new UserJpushMessage(entities.get(0));
	}

	@Override
	public List<UserJpushMessage> selectByMerchant(String merchantId) {
		UserJpushMessageQuery query = new UserJpushMessageQuery();
		query.setMerchantId(merchantId);
		query.setStatus(false);
		return list(query.toQueryWrapper()).stream().map(UserJpushMessage::new).collect(Collectors.toList());
	}
}